let recommendTimer = null;
export default {
  data() {
    return {
      recommendCount: [], // 推荐商品倒计时
    };
  },
  beforeDestroy() {
    // 推荐商品倒计时
    clearInterval(recommendTimer);
    recommendTimer = null;
  },
  methods: {
    initCount(data) {
      // 推荐商品——倒计时批量处理
      // 倒计时清除
      clearInterval(recommendTimer);
      recommendTimer = null;

      this.recommendCount = data.map(item => {
        return item.end_time;
      });

      // 暂时停止倒计时
      recommendTimer = setInterval(this.initSelfCount, 1000);
    },
    initSelfCount() {
      // 推荐商品——递减时间戳
      const len = this.recommendCount.length;
      for (let i = 0; i < len; i++) {
        if (this.recommendCount[i] > 1000) {
          this.recommendCount[i] = this.recommendCount[i] - 1000;
        } else {
          this.recommendCount[i] = 0;
        }
      }
      this.recommendCount.splice(0, 0);
    },
  },
};
